package com.zhk.ScriptManagement.controller;

import com.zhk.ScriptManagement.entity.ScriptRelationType;
import com.zhk.ScriptManagement.entity.ScriptType;
import com.zhk.ScriptManagement.entity.vo.ScriptInfoVo;
import com.zhk.ScriptManagement.service.ScriptService;
import com.zhk.ScriptManagement.util.CodeMsg;
import com.zhk.ScriptManagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 * @Author: zhouhongkun
 * @Description: 剧本controller
 * @Date: 2021/4/5 11:55
 */
@RestController
@RequestMapping("script")
public class ScriptController {
    @Autowired
    private ScriptService scriptService;


    /**
     * 模糊查询剧本
     * @param scriptName 剧本名称
     * @param scriptTypeId 剧本类型
     * @param scriptNum 剧本人数
     * @return
     */
    @GetMapping("getFuzzyScripts")
//    @RequiresPermissions(value = {"1","0"},logical = Logical.OR)
    public Result getFuzzyScripts(@RequestParam(value = "scriptName",defaultValue = "",required = false) String scriptName,
                                  @RequestParam(value = "scriptTypeId",defaultValue = "",required = false) Integer scriptTypeId,
                                  @RequestParam(value = "scriptNum",defaultValue = "",required = false) Integer scriptNum,
                                  @RequestParam(value = "size",defaultValue = "10",required = false) String size,
                                  @RequestParam(value = "num",defaultValue = "1",required = false) String num,
                                  @RequestParam("token") String token){
        return scriptService.getFuzzyScripts(scriptName,scriptTypeId,scriptNum,size,num,token);
    }

    /**
     * 根绝剧本id查询剧本信息
     * @param scriptId
     * @return
     */
    @GetMapping("getScriptByScriptId")
    public Result getScriptByScriptId(@RequestParam("scriptId") Integer scriptId){
        if(!Optional.ofNullable(scriptId).isPresent()){
            return Result.error(CodeMsg.PARAMETER_ISNULL,"参数不能为空");
        }
        return scriptService.getScriptByScriptId(scriptId);
    }

    /**
     * 添加剧本
     * @param scriptInfoVo
     * @return
     */
    @PostMapping("addScript")
    public Result addScript(@RequestBody ScriptInfoVo scriptInfoVo){
        if(!Optional.ofNullable(scriptInfoVo).isPresent()){
            return Result.error(CodeMsg.PARAMETER_ISNULL,"参数不能为空");
        }
        return scriptService.addScript(scriptInfoVo);
    }

    /**
     * 更新剧本
     * @param scriptInfoVo
     * @return
     */
    @PostMapping("updateScript")
    public Result updateScript(@RequestBody ScriptInfoVo scriptInfoVo){
        if(!Optional.ofNullable(scriptInfoVo).isPresent()){
            return Result.error(CodeMsg.PARAMETER_ISNULL,"参数不能为空");
        }
        return scriptService.updateScript(scriptInfoVo);
    }

    /**
     * 添加剧本类型信息
     * @param scriptType
     * @return
     */
    @PostMapping("addScriptType")
    public Result addScriptType(@RequestBody ScriptType scriptType){
        if(!Optional.ofNullable(scriptType).isPresent()){
            return Result.error(CodeMsg.PARAMETER_ISNULL,"参数不能为空");
        }
        return scriptService.addScriptType(scriptType);
    }

    /**
     * 修改剧本类型
     * @param scriptType
     * @return
     */
    @PostMapping("updateScriptType")
    public Result updateScriptType(@RequestBody ScriptType scriptType){
        if(!Optional.ofNullable(scriptType).isPresent()){
            return Result.error(CodeMsg.PARAMETER_ISNULL,"参数不能为空");
        }
        return scriptService.updateScriptType(scriptType);
    }

    /**
     * 获取剧本类型列表
     * @return
     */
    @GetMapping("getScriptTypes")
    public Result getScriptTypes(){
        return scriptService.getScriptTypes();
    }

}
